#pragma once
#include "cocos2d.h"

using namespace cocos2d;

class NameLayer : public Layer, public cocos2d::IMEDelegate, public cocos2d::TextFieldDelegate
{
public:
	NameLayer();
	~NameLayer();

	// Layer
	virtual void onEnter() override;
	virtual void onExit() override;

	virtual void onClickTrackNode(bool bClicked);
	virtual void keyboardWillShow(cocos2d::IMEKeyboardNotificationInfo& info);

	bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
	void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);

	virtual bool onTextFieldAttachWithIME(cocos2d::TextFieldTTF*  sender) override;
	virtual bool onTextFieldDetachWithIME(cocos2d::TextFieldTTF*  sender) override;
	virtual bool onTextFieldInsertText(cocos2d::TextFieldTTF*  sender, const char * text, size_t nLen) override;
	virtual bool onTextFieldDeleteBackward(cocos2d::TextFieldTTF*  sender, const char * delText, size_t nLen) override;
	virtual bool onDraw(cocos2d::TextFieldTTF*  sender);

	void callbackRemoveNodeWhenDidAction(Node * node);
	void typeOK();
	void typeCancel();
	void changeName();

	virtual bool init();
	CREATE_FUNC(NameLayer);
private:
	EventListener* m_listener;
	Node* _trackNode;
	cocos2d::Vec2  _beginPos;

	cocos2d::TextFieldTTF*    _textField;
	cocos2d::Action*          _textFieldAction;
	bool _action;
	int _charLimit;       // the textfield max char limit
	std::string myName;
};

